﻿<Window x:Class="_11.DataBinding.SimpleDataBinding"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:_11.DataBinding"
        Title="SimpleDataBinding" Height="118" Width="402">
    <Window.Resources>
        <local:Person x:Key="author" Name="Cheka" Age="30"/> 
        <Thickness x:Key="Margin" Left="5" Top="5" Right="5" Bottom="5"/>
        <Style x:Key="headerLabelStyle" TargetType="Label">
            <Setter Property="HorizontalContentAlignment" Value="Right"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Margin" Value="{StaticResource Margin}"/>
        </Style>
        <Style x:Key="contentLabelStyle" TargetType="Label">
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Margin" Value="{StaticResource Margin}"/>
            <Setter Property="Background" Value="PowderBlue"/>
        </Style>
    </Window.Resources>
    <!--note: DataContext can be set at both XAML and code-behind-->
    <Grid DataContext="{StaticResource author}">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition  />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" />
            <ColumnDefinition Width="2*" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
        <Label Grid.Row="0" Grid.Column="0" Content="Name: "
               Style="{StaticResource headerLabelStyle}"/>
        <Label Grid.Row="1" Grid.Column="0" Content="Age: "
               Style="{StaticResource headerLabelStyle}"/>
        <!--note: short hand binding syntax-->
        <Label Grid.Row="0" Grid.Column="1" 
               Style="{StaticResource contentLabelStyle}"
               Content="{Binding Path=Name, Mode=OneWay}"/>
        <!--note: long hand binding syntax-->
        <Label Grid.Row="1" Grid.Column="1" 
               Name="lblAge"
               Style="{StaticResource contentLabelStyle}">
            <Binding Path="Age" Mode="OneWay"/>
        </Label>
        <!--note: bind the property of one control to property of another control-->
    	<Button Grid.Row="1" Grid.Column="2"  Name="btnYounger" Content="Younger!" 
                Margin="{StaticResource Margin}"
                Click="btnYouger_Clicked"
                Background="{Binding ElementName=lblAge, Path=Background}"/>
    </Grid>
</Window>
